from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from backend.apps.recruit.models import Enterprise, City, Recruit


class EnterpriseSerializerSimple(serializers.ModelSerializer):

    class Meta:
        model = Enterprise
        fields = ('id', 'name','labels','logo','recruits','summary')


class RecruitSerializerSimple(serializers.ModelSerializer):
    enterprise = EnterpriseSerializerSimple(read_only=True)

    class Meta:
        model = Recruit
        fields = ('id', 'jobname','salary','condition','education','type','city','createtime','enterprise','labels')




# 企业的序列化器
class EnterpriseSerializers(ModelSerializer):
    recruits = RecruitSerializerSimple(read_only=True, many=True)
    class Meta:
        model = Enterprise
        fields = "__all__"

# 城市的序列化器
class CitySerializers(ModelSerializer):
    # 获取内容 Meta
    class Meta:
        model = City
        fields = "__all__"

# 职位的序列化器
class RecruitSerializers(ModelSerializer):
    enterprise = EnterpriseSerializers(read_only=True)
    class Meta:
        model = Recruit
        fields = "__all__"